home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / runtime / fail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-24  |  866 b   |  57 lines  |  [TEXT/MPS ]

  1. /* Raising exceptions from C. */
  2.  
  3. #include "alloc.h"
  4. #include "fail.h"
  5. #include "memory.h"
  6. #include "mlvalues.h"
  7. #include "signals.h"
  8.  
  9. struct longjmp_buffer * external_raise;
  10. value exn_bucket;
  11.  
  12. void mlraise(v)
  13.      value v;
  14. {
  15.   in_blocking_section = 0;
  16.   exn_bucket = v;
  17.   longjmp(external_raise->buf, 1);
  18. }
  19.  
  20. void raise_with_arg(tag, arg)
  21.      tag_t tag;
  22.      value arg;
  23. {
  24.   value bucket;
  25.   Push_roots (a, 1);
  26.   a[0] = arg;
  27.  
  28.   bucket = alloc (1, tag);
  29.   Field(bucket, 0) = a[0];
  30.   Pop_roots ();
  31.   mlraise(bucket);
  32. }
  33.  
  34. void raise_with_string(tag, msg)
  35.      tag_t tag;
  36.      char * msg;
  37. {
  38.   raise_with_arg(tag, copy_string(msg));
  39. }
  40.  
  41. void failwith (msg)
  42.      char * msg;
  43. {
  44.   raise_with_string(FAILURE_EXN, msg);
  45. }
  46.  
  47. void invalid_argument (msg)
  48.      char * msg;
  49. {
  50.   raise_with_string(INVALID_EXN, msg);
  51. }
  52.  
  53. void raise_out_of_memory()
  54. {
  55.   mlraise(Atom(OUT_OF_MEMORY_EXN));
  56. }
  57.